import { _decorator, Component, Label, native, Node, sys } from 'cc';
const { ccclass, property } = _decorator;

@ccclass('MainUI')
export class MainUI extends Component {


    @property(Label)
    Label_Tips: Label;

    protected onEnable(): void {
        if (sys.isNative) {
            if (sys.os == sys.OS.ANDROID) {
                let self = this;
                //绑定java, google登录回调
                native.jsbBridgeWrapper.addNativeEventListener("onGoogleLoginInCallBack", (loginInParams: string) => {

                    self.Label_Tips.string = loginInParams;
                });
            }
        }

    }

    protected onDisable(): void {
        native.jsbBridgeWrapper.removeAllListenersForEvent("onGoogleLoginInCallBack");
    }


    onLoginButtonClicked() {

        if (sys.isNative) {
            let ret = 0;
            if (sys.os == sys.OS.ANDROID) {
                let LoginParams: string = "0";
                // ret = jsb.reflection.callStaticMethod("org/cocos2dx/javascript/AppActivity", "loginGoogle", "(Ljava/lang/String;)V", this._callBackPrefix + cbKey + funcParams);
                ret = native.reflection.callStaticMethod("com/cocos/game/AppActivity", "loginGoogle", "()V");

                // dispatchEventToNative 只支持2个参数，第一个是事件名字，第二个是事件参数，都是字符串格式。
                // let loginInArgs: string = "登录参数";
                // native.jsbBridgeWrapper.dispatchEventToNative("onGoogleLogIn", loginInArgs);
            }
        }
    }


    onBuyShopItemButtonClicked() {
        if (sys.isNative) {
            let ret = 0;
            if (sys.os == sys.OS.ANDROID) {
                let iap_Id: string = "iap_001";
                let orderId: string = "0";
                ret = native.reflection.callStaticMethod("com/cocos/game/AppActivity", "tryGooglePay", "(Ljava/lang/String;Ljava/lang/String;)V", iap_Id, orderId);

            }
        }
    }

    onButton2Clicked() {

        if (sys.isNative) {
            let ret = 0;
            if (sys.os == sys.OS.ANDROID) {
                ret = native.reflection.callStaticMethod("com/cocos/game/AppActivity", "querySkuDetailsAsync", "()V");

                // dispatchEventToNative 只支持2个参数，第一个是事件名字，第二个是事件参数，都是字符串格式。
                // let loginInArgs: string = "登录参数";
                // native.jsbBridgeWrapper.dispatchEventToNative("querySkuDetailsAsync");
            }
        }
    }

    onLogoutButtonClicked() {

        if (sys.isNative) {
            let ret = 0;
            if (sys.os == sys.OS.ANDROID) {
                let LoginParams: string = "0";
                // ret = jsb.reflection.callStaticMethod("org/cocos2dx/javascript/AppActivity", "loginGoogle", "(Ljava/lang/String;)V", this._callBackPrefix + cbKey + funcParams);
                // ret = native.reflection.callStaticMethod("com/cocos/game/AppActivity", "logOutGoogle", "()V");

                // dispatchEventToNative 只支持2个参数，第一个是事件名字，第二个是事件参数，都是字符串格式。
                // let loginInArgs: string = "登录参数";
                native.jsbBridgeWrapper.dispatchEventToNative("onGoogleLogOut");
            }
        }

    }
}


